<?php
/**
 * Created by PhpStorm.
 * User: One
 * Date: 2018/1/23
 * Time: 10:12
 */
//region 关于登录-注册
//region  生成密钥
/**
 * 生成密钥
 * @param $username 用户名
 * @param $password 密码
 * @return string   密钥
 */
function generateToken($username, $password){
    return md5(md5(md5($username) . time()) . $password);
}

//获取token
function getToken(){
    return md5(time().rand(10000,99999));
}

//endregion

//region  二维数组去重
/**
 * 二维数组去重
 */
function unique_arr($array2D, $stkeep = false, $ndformat = true){
    // 判断是否保留一级数组键 (一级数组键可以为非数字)
    if ($stkeep) $stArr = array_keys($array2D);

    // 判断是否保留二级数组键 (所有二级数组键必须相同)
    if ($ndformat) $ndArr = array_keys(end($array2D));

    //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
    foreach ($array2D as $v) {
        $v = join(",", $v);
        $temp[] = $v;
    }

    //去掉重复的字符串,也就是重复的一维数组
    $temp = array_unique($temp);

    //再将拆开的数组重新组装
    foreach ($temp as $k => $v) {
        if ($stkeep) $k = $stArr[$k];
        if ($ndformat) {
            $tempArr = explode(",", $v);
            foreach ($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;
        } else $output[$k] = explode(",", $v);
    }

    return $output;
}

//endregion

//region   获取随机数
/**
 * 获取随机数 $length为长度
 */
function randomkeys($length){
    $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
    $key = '';
    for ($i = 0; $i < $length; $i++) {
        $key .= $pattern{mt_rand(0, 61)};    //生成php随机数
    }
    return $key;
}

function randnumkeys($length){
    $pattern = '1234567890';
    $key = '';
    for ($i = 0; $i < $length; $i++) {
        $key .= $pattern{mt_rand(0, 9)};    //生成php随机数
    }
    return $key;
}

//endregion

//region  获取时间日期
/**
 *获取时间日期
 * @param $time 时间
 */
function getdates($time = ''){
    if( $time == '' ){
        return date('Y-m-d H:i:s');
    }else{
        return date('Y-m-d H:i:s',$time);
    }
}
//endregion

//检查日期并处理日期	
function changeDate($date){
	if( $date == 0 ){
		return "";
	}else{
		return date('Y-m-d',$date);
	}
}

//检查日期并处理日期
function changeDateTime($date){
	if( $date == 0 ){
		return "";
	}else{
		return date('Y-m-d H:i:s',$date);
	}
}

//region 根据两点间的经纬度计算距离
/**
 * @desc 根据两点间的经纬度计算距离
 * @param float $lat 纬度值
 * @param float $lng 经度值
 */
function getDistance($lat1, $lng1, $lat2, $lng2){
    $earthRadius = 6367000; //approximate radius of earth in meters
    /*
    Convert these degrees to radians
    to work with the formula
    */
    $lat1 = ($lat1 * pi()) / 180;
    $lng1 = ($lng1 * pi()) / 180;
    $lat2 = ($lat2 * pi()) / 180;
    $lng2 = ($lng2 * pi()) / 180;
    /*
    Using the
    Haversine formula
    http://en.wikipedia.org/wiki/Haversine_formula
    calculate the distance
    */
    $calcLongitude = $lng2 - $lng1;
    $calcLatitude = $lat2 - $lat1;
    $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
    $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
    $calculatedDistance = $earthRadius * $stepTwo;
    return round($calculatedDistance);
}

//endregion

//region  计算某个经纬度的周围某段距离的正方形的四个点
/**
* 计算某个经纬度的周围某段距离的正方形的四个点
* @param radius 地球半径 平均6371km
* @param lng float 经度
* @param lat float 纬度
* @param distance float 该点所在圆的半径，该圆与此正方形内切，默认值为1千米
* @return array 正方形的四个点的经纬度坐标
 */
function returnSquarePoint($lng, $lat, $distance = 1, $radius = 6371){
    $dlng = 2 * asin(sin($distance / (2 * $radius)) / cos(deg2rad($lat)));
    $dlng = rad2deg($dlng);

    $dlat = $distance / $radius;
    $dlat = rad2deg($dlat);

    return array(
        'left-top' => array(
            'lat' => $lat + $dlat,
            'lng' => $lng - $dlng
        ),
        'right-top' => array(
             'lat' => $lat + $dlat,
             'lng' => $lng + $dlng
         ),
         'left-bottom' => array(
             'lat' => $lat - $dlat,
             'lng' => $lng - $dlng
        ),
        'right-bottom' => array(
            'lat' => $lat - $dlat,
            'lng' => $lng + $dlng
         )
    );
 }
//endregion

//region  Excel导出
/**
 * Excel导出
 * @param $tableheader 标头数组
 * @param $data 二维数据集
 * @param string $filename 导出文件名
 */
function excelOutput($tableheader, $data, $filename = 'data'){
    //创建对象
    $excel = new \PHPExcel();
    //Excel表格式,这里简略写了8列
    $letter = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');   //可以写多列，但不能写少
//表头数组
// $tableheader = array('学号','姓名','性别','年龄','班级');
//填充表头信息
    for ($i = 0; $i < count($tableheader); $i++) {
        $excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
    }
//表格数组
//    $data = array(
//        array('1','小王','男','20','100'),
//        array('2','小李','男','20','101'),
//        array('2','小李','男','20','101'),
//        array('3','小张','女','20','102'),
//        array('2','小李','男','20','101'),
//        array('3','小张','女','20','102'),
//        array('4','小赵','女','20','103')
//    );
    //填充表格信息
    for ($i = 2; $i <= count($data) + 1; $i++) {
        $j = 0;
        foreach ($data[$i - 2] as $key => $value) {
            $excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
            $j++;
        }
    }
    //创建Excel输入对象
    $write = new \PHPExcel_Writer_Excel5($excel);
    ob_end_clean();
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="' . $filename . '.xls"');   //默认文件名
    header("Content-Transfer-Encoding:binary");
    $write->save('php://output');
}
//endregion

/**
 * 验证电话号码
 */
function isMobile($num) {
    if (!is_numeric($num)) {
        return false;
    }
    return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,3,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $num) ? true : false;
}

function curl_get($url = '', $options = array()){

    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_TIMEOUT, 5);

    if (!empty($options)) {

        curl_setopt_array($ch, $options);

    }

    $data = curl_exec($ch);

    curl_close($ch);

    return $data;

}

//region  生成订单编号(微信订单)
function createWxNo()
{
    return date('YmdHis') . str_pad(mt_rand(1, 9999), 6, '0', STR_PAD_LEFT);
}

//region  生成订单编号
function createOrderNo()
{
    return date('YmdHis') . str_pad(mt_rand(1, 99), 2, '0', STR_PAD_LEFT);
}

/**
 * @by JYuan
 * @param $log_str 保存的日志信息
 */
function addFileLog($log_str){
    $time = time();
    $file_name = date("Y-m-d",$time).".txt";
    $current_time = date("Y-m-d H:i:s",$time);

    $log_file = fopen("./Public/Log/".$file_name, "a+") or die("Unable to open file!");
    fwrite($log_file, $current_time." : ".$log_str."\r\n");
    fclose($log_file);
}

function getProvinceData($province_code=""){
    $province_array = array('110000'=>'北京市',
        '120000'=>'天津市',
        '130000'=>'河北省',
        '140000'=>'山西省',
        '150000'=>'内蒙古自治区',
        '210000'=>'辽宁省',
        '220000'=>'吉林省',
        '230000'=>'黑龙江省',
        '310000'=>'上海市',
        '320000'=>'江苏省',
        '330000'=>'浙江省',
        '340000'=>'安徽省',
        '350000'=>'福建省',
        '360000'=>'江西省',
        '370000'=>'山东省',
        '410000'=>'河南省',
        '420000'=>'湖北省',
        '430000'=>'湖南省',
        '440000'=>'广东省',
        '450000'=>'广西壮族自治区',
        '460000'=>'海南省',
        '500000'=>'重庆市',
        '510000'=>'四川省',
        '520000'=>'贵州省',
        '530000'=>'云南省',
        '540000'=>'西藏自治区',
        '610000'=>'陕西省',
        '620000'=>'甘肃省',
        '630000'=>'青海省',
        '640000'=>'宁夏回族自治区',
        '650000'=>'新疆维吾尔自治区',
        '710000'=>'台湾省',
        '810000'=>'香港特别行政区',
        '820000'=>'澳门特别行政区'
    );
    if(!empty($province_code)){
        return $province_array[$province_code];
    }else{
        return $province_array;
    }
}

function getCityData($province_code,$city_code=""){
    $city_data = array('110000'=>array('110100'=>'市辖区','110200'=>'县'),
        '120000'=>array('120100'=>'市辖区','120200'=>'县'),
        '130000'=>array('130100'=>'石家庄市','130200'=>'唐山市','130300'=>'秦皇岛市','130400'=>'邯郸市','130500'=>'邢台市','130600'=>'保定市','130700'=>'张家口市','130800'=>'承德市','130900'=>'沧州市','131000'=>'廊坊市','131100'=>'衡水市'),
        '140000'=>array('140100'=>'太原市','140200'=>'大同市','140300'=>'阳泉市','140400'=>'长治市','140500'=>'晋城市','140600'=>'朔州市','140700'=>'晋中市','140800'=>'运城市','140900'=>'忻州市','141000'=>'临汾市','141100'=>'吕梁市'),
        '150000'=>array('150100'=>'呼和浩特市','150200'=>'包头市','150300'=>'乌海市','150400'=>'赤峰市','150500'=>'通辽市','150600'=>'鄂尔多斯市','150700'=>'呼伦贝尔市','150800'=>'巴彦淖尔市','150900'=>'乌兰察布市','152200'=>'兴安盟','152500'=>'锡林郭勒盟','152900'=>'阿拉善盟'),
        '210000'=>array('210100'=>'沈阳市','210200'=>'大连市','210300'=>'鞍山市','210400'=>'抚顺市','210500'=>'本溪市','210600'=>'丹东市','210700'=>'锦州市','210800'=>'营口市','210900'=>'阜新市','211000'=>'辽阳市','211100'=>'盘锦市','211200'=>'铁岭市','211300'=>'朝阳市','211400'=>'葫芦岛市'),
        '220000'=>array('220100'=>'长春市','220200'=>'吉林市','220300'=>'四平市','220400'=>'辽源市','220500'=>'通化市','220600'=>'白山市','220700'=>'松原市','220800'=>'白城市','222400'=>'延边朝鲜族自治州'),
        '230000'=>array('230100'=>'哈尔滨市','230200'=>'齐齐哈尔市','230300'=>'鸡西市','230400'=>'鹤岗市','230500'=>'双鸭山市','230600'=>'大庆市','230700'=>'伊春市','230800'=>'佳木斯市','230900'=>'七台河市','231000'=>'牡丹江市','231100'=>'黑河市','231200'=>'绥化市','232700'=>'大兴安岭地区'),
        '310000'=>array('310100'=>'市辖区','310200'=>'县'),
        '320000'=>array('320100'=>'南京市','320200'=>'无锡市','320300'=>'徐州市','320400'=>'常州市','320500'=>'苏州市','320600'=>'南通市','320700'=>'连云港市','320800'=>'淮安市','320900'=>'盐城市','321000'=>'扬州市','321100'=>'镇江市','321200'=>'泰州市','321300'=>'宿迁市'),
        '330000'=>array('330100'=>'杭州市','330200'=>'宁波市','330300'=>'温州市','330400'=>'嘉兴市','330500'=>'湖州市','330600'=>'绍兴市','330700'=>'金华市','330800'=>'衢州市','330900'=>'舟山市','331000'=>'台州市','331100'=>'丽水市'),
        '340000'=>array('340100'=>'合肥市','340200'=>'芜湖市','340300'=>'蚌埠市','340400'=>'淮南市','340500'=>'马鞍山市','340600'=>'淮北市','340700'=>'铜陵市','340800'=>'安庆市','341000'=>'黄山市','341100'=>'滁州市','341200'=>'阜阳市','341300'=>'宿州市','341400'=>'巢湖市','341500'=>'六安市','341600'=>'亳州市','341700'=>'池州市','341800'=>'宣城市'),
        '350000'=>array('350100'=>'福州市','350200'=>'厦门市','350300'=>'莆田市','350400'=>'三明市','350500'=>'泉州市','350600'=>'漳州市','350700'=>'南平市','350800'=>'龙岩市','350900'=>'宁德市'),
        '360000'=>array('360100'=>'南昌市','360200'=>'景德镇市','360300'=>'萍乡市','360400'=>'九江市','360500'=>'新余市','360600'=>'鹰潭市','360700'=>'赣州市','360800'=>'吉安市','360900'=>'宜春市','361000'=>'抚州市','361100'=>'上饶市'),
        '370000'=>array('370100'=>'济南市','370200'=>'青岛市','370300'=>'淄博市','370400'=>'枣庄市','370500'=>'东营市','370600'=>'烟台市','370700'=>'潍坊市','370800'=>'济宁市','370900'=>'泰安市','371000'=>'威海市','371100'=>'日照市','371200'=>'莱芜市','371300'=>'临沂市','371400'=>'德州市','371500'=>'聊城市','371600'=>'滨州市','371700'=>'荷泽市'),
        '410000'=>array('410100'=>'郑州市','410200'=>'开封市','410300'=>'洛阳市','410400'=>'平顶山市','410500'=>'安阳市','410600'=>'鹤壁市','410700'=>'新乡市','410800'=>'焦作市','410900'=>'濮阳市','411000'=>'许昌市','411100'=>'漯河市','411200'=>'三门峡市','411300'=>'南阳市','411400'=>'商丘市','411500'=>'信阳市','411600'=>'周口市','411700'=>'驻马店市'),
        '420000'=>array('420100'=>'武汉市','420200'=>'黄石市','420300'=>'十堰市','420500'=>'宜昌市','420600'=>'襄樊市','420700'=>'鄂州市','420800'=>'荆门市','420900'=>'孝感市','421000'=>'荆州市','421100'=>'黄冈市','421200'=>'咸宁市','421300'=>'随州市','422800'=>'恩施土家族苗族自治州','429000'=>'省直辖行政单位'),
        '430000'=>array('430100'=>'长沙市','430200'=>'株洲市','430300'=>'湘潭市','430400'=>'衡阳市','430500'=>'邵阳市','430600'=>'岳阳市','430700'=>'常德市','430800'=>'张家界市','430900'=>'益阳市','431000'=>'郴州市','431100'=>'永州市','431200'=>'怀化市','431300'=>'娄底市','433100'=>'湘西土家族苗族自治州'),
        '440000'=>array('440100'=>'广州市','440200'=>'韶关市','440300'=>'深圳市','440400'=>'珠海市','440500'=>'汕头市','440600'=>'佛山市','440700'=>'江门市','440800'=>'湛江市','440900'=>'茂名市','441200'=>'肇庆市','441300'=>'惠州市','441400'=>'梅州市','441500'=>'汕尾市','441600'=>'河源市','441700'=>'阳江市','441800'=>'清远市','441900'=>'东莞市','442000'=>'中山市','445100'=>'潮州市','445200'=>'揭阳市','445300'=>'云浮市'),
        '450000'=>array('450100'=>'南宁市','450200'=>'柳州市','450300'=>'桂林市','450400'=>'梧州市','450500'=>'北海市','450600'=>'防城港市','450700'=>'钦州市','450800'=>'贵港市','450900'=>'玉林市','451000'=>'百色市','451100'=>'贺州市','451200'=>'河池市','451300'=>'来宾市','451400'=>'崇左市'),
        '460000'=>array('460100'=>'海口市','460200'=>'三亚市','469000'=>'省直辖县级行政单位'),
        '500000'=>array('500100'=>'市辖区','500200'=>'县','500300'=>'市'),
        '510000'=>array('510100'=>'成都市','510300'=>'自贡市','510400'=>'攀枝花市','510500'=>'泸州市','510600'=>'德阳市','510700'=>'绵阳市','510800'=>'广元市','510900'=>'遂宁市','511000'=>'内江市','511100'=>'乐山市','511300'=>'南充市','511400'=>'眉山市','511500'=>'宜宾市','511600'=>'广安市','511700'=>'达州市','511800'=>'雅安市','511900'=>'巴中市','512000'=>'资阳市','513200'=>'阿坝藏族羌族自治州','513300'=>'甘孜藏族自治州','513400'=>'凉山彝族自治州'),
        '520000'=>array('520100'=>'贵阳市','520200'=>'六盘水市','520300'=>'遵义市','520400'=>'安顺市','522200'=>'铜仁地区','522300'=>'黔西南布依族苗族自治州','522400'=>'毕节地区','522600'=>'黔东南苗族侗族自治州','522700'=>'黔南布依族苗族自治州'),
        '530000'=>array('530100'=>'昆明市','530300'=>'曲靖市','530400'=>'玉溪市','530500'=>'保山市','530600'=>'昭通市','530700'=>'丽江市','530800'=>'思茅市','530900'=>'临沧市','532300'=>'楚雄彝族自治州','532500'=>'红河哈尼族彝族自治州','532600'=>'文山壮族苗族自治州','532800'=>'西双版纳傣族自治州','532900'=>'大理白族自治州','533100'=>'德宏傣族景颇族自治州','533300'=>'怒江傈僳族自治州','533400'=>'迪庆藏族自治州'),
        '540000'=>array('540100'=>'拉萨市','542100'=>'昌都地区','542200'=>'山南地区','542300'=>'日喀则地区','542400'=>'那曲地区','542500'=>'阿里地区','542600'=>'林芝地区'),
        '610000'=>array('610100'=>'西安市','610200'=>'铜川市','610300'=>'宝鸡市','610400'=>'咸阳市','610500'=>'渭南市','610600'=>'延安市','610700'=>'汉中市','610800'=>'榆林市','610900'=>'安康市','611000'=>'商洛市'),
        '620000'=>array('620100'=>'兰州市','620200'=>'嘉峪关市','620300'=>'金昌市','620400'=>'白银市','620500'=>'天水市','620600'=>'武威市','620700'=>'张掖市','620800'=>'平凉市','620900'=>'酒泉市','621000'=>'庆阳市','621100'=>'定西市','621200'=>'陇南市','622900'=>'临夏回族自治州','623000'=>'甘南藏族自治州'),
        '630000'=>array('630100'=>'西宁市','632100'=>'海东地区','632200'=>'海北藏族自治州','632300'=>'黄南藏族自治州','632500'=>'海南藏族自治州','632600'=>'果洛藏族自治州','632700'=>'玉树藏族自治州','632800'=>'海西蒙古族藏族自治州'),
        '640000'=>array('640100'=>'银川市','640200'=>'石嘴山市','640300'=>'吴忠市','640400'=>'固原市','640500'=>'中卫市'),
        '650000'=>array('650100'=>'乌鲁木齐市','650200'=>'克拉玛依市','652100'=>'吐鲁番地区','652200'=>'哈密地区','652300'=>'昌吉回族自治州','652700'=>'博尔塔拉蒙古自治州','652800'=>'巴音郭楞蒙古自治州','652900'=>'阿克苏地区','653000'=>'克孜勒苏柯尔克孜自治州','653100'=>'喀什地区','653200'=>'和田地区','654000'=>'伊犁哈萨克自治州','654200'=>'塔城地区','654300'=>'阿勒泰地区','659000'=>'省直辖行政单位'),
        '710000'=>array(),
        '810000'=>array(),
        '820000'=>array()
    );
    if(!empty($city_code)){
        return $city_data[$province_code][$city_code];
    }else{
        return $city_data[$province_code];
    }
}

function getCurlData($url){
    $curl = curl_init();
    //设置抓取的url
    curl_setopt($curl, CURLOPT_URL, $url);
    //设置头文件的信息作为数据流输出
    //curl_setopt($curl, CURLOPT_HEADER, 0);
    //设置获取的信息以文件流的形式返回，而不是直接输出。
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    //执行命令
    $data = curl_exec($curl);
    //关闭URL请求
    curl_close($curl);
    return $data;
}

/*****************  汇聚支付方法   ******************/

//加密方法
function hmacRequest($params, $key, $encryptType = "1")
{
    ksort($params);
    if ("1" == $encryptType) {
        return md5(implode("", $params) . $key);
    } else {
        $private_key = openssl_pkey_get_private($key);
        $params = implode("", $params);
        openssl_sign($params, $sign, $private_key, OPENSSL_ALGO_MD5);
        openssl_free_key($private_key);
        $sign = base64_encode($sign);
        return $sign;
    }
}

//加密方法
function hmacRequest2($params, $key, $encryptType = "1")
{
    if ("1" == $encryptType) {
        return md5(implode("", $params) . $key);
    } else {
        $private_key = openssl_pkey_get_private($key);
        $params = implode("", $params);
        openssl_sign($params, $sign, $private_key, OPENSSL_ALGO_MD5);
        openssl_free_key($private_key);
        $sign = base64_encode($sign);
        return $sign;
    }
}

function jy_post($url,$post_data='',$get_json=1){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if($post_data){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }
    $headers = array(
        "Content-type: application/json;",
    );

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $output = curl_exec($ch);
    curl_close($ch);
    if($get_json==1) {
        return json_decode($output, true);
    }else{
        return $output;
    }
}

function jy_raw_post($url, $data_string) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'X-AjaxPro-Method:ShowList',
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($data_string))
    );
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

//生成订单号
function getOrderId()
{
    return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
}

/**
 * POST请求
 */
function http_post($url, $params)
{
    if (function_exists('curl_init')) { // curl方式
        $oCurl = curl_init();
        if (stripos($url, 'https://') !== FALSE) {
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
        }
        $string = $params;
        if (is_array($params)) {
            $aPOST = array();
            foreach ($params as $key => $val) {
                $aPOST[] = $key . '=' . urlencode($val);
            }
            $string = join('&', $aPOST);
        }
        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($oCurl, CURLOPT_POST, TRUE);
        curl_setopt($oCurl, CURLOPT_POSTFIELDS, $string);
        $response = curl_exec($oCurl);
        curl_close($oCurl);
        return $response;
//        return json_decode($response, true);
    } elseif (function_exists('stream_context_create')) { // php5.3以上
        $opts = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type: application/x-www-form-urlencoded',
                'content' => http_build_query($params),
            )
        );
        $_opts = stream_context_get_params(stream_context_get_default());
        $context = stream_context_create(array_merge_recursive($_opts['options'], $opts));
        return file_get_contents($url, false, $context);
//        return json_decode(file_get_contents($url, false, $context), true);
    } else {
        return FALSE;
    }
}

/**
 * POST请求
 */
function http_post_json($url, $params,$contentType=false){
    if (function_exists('curl_init')) { // curl方式
        $oCurl = curl_init();
        if (stripos($url, 'https://') !== FALSE) {
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
        }
        $string = $params;
        if (is_array($params)) {
            $aPOST = array();
            foreach ($params as $key => $val) {
                $aPOST[] = $key . '=' . urlencode($val);
            }
            $string = join('&', $aPOST);
        }
        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($oCurl, CURLOPT_POST, TRUE);
        //$contentType json处理
        if($contentType){
            $headers = array(
                "Content-type: application/json;charset='utf-8'",
            );

            curl_setopt($oCurl, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($oCurl, CURLOPT_POSTFIELDS, json_encode($params));
        }else{
            curl_setopt($oCurl, CURLOPT_POSTFIELDS, $string);
        }
        $response = curl_exec($oCurl);
        curl_close($oCurl);
        return $response;
//        return json_decode($response, true);
    } elseif (function_exists('stream_context_create')) { // php5.3以上
        $opts = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type: application/x-www-form-urlencoded',
                'content' => http_build_query($params),
            )
        );
        $_opts = stream_context_get_params(stream_context_get_default());
        $context = stream_context_create(array_merge_recursive($_opts['options'], $opts));
        return file_get_contents($url, false, $context);
//        return json_decode(file_get_contents($url, false, $context), true);
    } else {
        return FALSE;
    }
}

//转换数组中的中文
function urlParamsEncode($params){
    $params['p2_MerchantName'] = urlencode($params['p2_MerchantName']);
    $params['q4_ProductName'] = urlencode($params['q4_ProductName']);
    $params['s1_PayerName'] = urlencode($params['s1_PayerName']);
    return $params;
}
/*****************  END汇聚支付方法   ******************/

function FDB($table){
    return M("financial_ecosystem.{$table}",'fes_');
}

function HDB($table){
    return M("financial_help_loan.{$table}",'fes_help_');
}

function RDB($table){
    return M("financial_risk_manage.{$table}",'fes_risk_');
}